package com.sun.study;

import com.sun.study.utils.jdbcUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author Sun
 * @Date 2020/4/11 22:52
 * @Version 1.0
 */
public class Testinsert {
    public static void main(String[] args) {

        Connection connection = null;
        Statement statement = null;
        ResultSet rs = null;

        try {
            // 直接通过工具类调用方法获取连接
            connection = jdbcUtils.getConnection();

            // 获取SQL的执行对象
            statement = connection.createStatement();

            // 执行sql
            String  sql = "insert into course values('C06','云计算')";

            int i = statement.executeUpdate(sql);//返回受影响的行数

            if (i > 0){
                System.out.println("插入成功");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            //释放资源
            jdbcUtils.Release(connection, statement, rs);
        }

    }
}
